/*
 * @Description: 
 * @Author: fhw
 * @Date: 2022-12-06 15:26:51
 */
import { Controller, Get, HttpCode, Query, UseGuards } from '@nestjs/common';
import { ApiResponse, ApiOperation, ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { ChatRecordService } from './chat-record.service';
import { GetUserChatRecord } from './dto/chat-record.dto';
import { UserChatRecordResult } from './entities/user-chat-record.entity';
import { AuthGuard } from '@nestjs/passport';
import { isNil } from 'ramda';
@ApiTags('聊天记录')
@Controller('chat-record')
export class ChatRecordController {
  constructor(private readonly chatRecordService: ChatRecordService) { }
  @HttpCode(200)
  @Get('/getUserChatRecord')
  @ApiResponse({
    status: 200,
    description: '获取用户聊天记录',
    type: UserChatRecordResult,
  })
  @ApiOperation({ tags: ['聊天记录'], summary: '获取用户聊天记录', operationId: 'getUserChatRecord' })
  @UseGuards(AuthGuard('jwt'))//jwt策略，身份鉴权
  @ApiBearerAuth() // swagger文档设置token
  getUserChatRecord(@Query() params: GetUserChatRecord) {
    if (isNil(params.group_id)){
      return this.chatRecordService.getUserChatRecord(params)
    } else {
      return this.chatRecordService.getGroupChatRecord(params)
    }
  }
}
